
#pragma once

#include <cmath>
#include <ttg/math.h>
#include <ttg/pipeline.h>
#include "Primitives.h"

using namespace ttg::pipeline;

//Tests pipeline on 2x2 matrix without saddle point.
//In case of success returns true.
bool pipelineTest1(Pipeline<matrix<int> *, point<size_t>> &pl)
{
	//Generating matrix for "Orlyanka" game.
	matrix<int> m(2, 2);
	m(0, 0) = 0;
	m(1, 0) = 1;
	m(1, 1) = 0;
	m(0, 1) = 1;
	//Testing.
	return pl.run(&m).size() == 0;
}

//Creates big matrix, which is filled by 1.
//In case of success returns true.
bool pipelineTest2(Pipeline<matrix<int> *, point<size_t>> &pl)
{
	//Generating matrix.
	matrix<int> m(64, 64);
	for (size_t j = 0; j < m.getWidth(); j++)
		for (size_t i = 0; i < m.getHeight(); i++)
			m(i, j) = 1;
	//Testing.
	std::vector<point<size_t>> res = pl.run(&m);
	return res.size() == 64 * 64;
}

//Creates big specific matrix with one saddle point.
//In case of success returns true.
bool pipelineTest3(Pipeline<matrix<int> *, point<size_t>> &pl)
{
	//Generating matrix.
	matrix<int> m(128, 64);
	for (size_t j = 0; j < m.getWidth(); j++)
		for (size_t i = 0; i < m.getHeight(); i++)
			m(i, j) = 0;
	for (size_t j = 0; j < m.getWidth(); j++)
		m(42, j) = 1 + abs(17 - (int)j);
	//Testing.
	std::vector<point<size_t>> res = pl.run(&m);
	return res.size() == 1 && res[0].x == 42 && res[0].y == 17;
}

//Creates matrix with random elements.
bool pipelineTest4(Pipeline<matrix<int> *, point<size_t>> &pl)
{
	//Generating matrix.
	matrix<int> m(4 * 1024, 4 * 1024);
	for (size_t j = 0; j < m.getWidth(); j++)
		for (size_t i = 0; i < m.getHeight(); i++)
			m(i, j) = ttg::math::getIntRandom(-128, 128);
	//Calculating.
	return pl.run(&m).size() <= m.getWidth() * m.getHeight();
}
